<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Expert_index_module extends CI_Module {
    private   $data ;
    private $sitename;

    public function __construct()
    {
        parent::__construct();
        $this->load->model('expert.Expert_model');
        $this->load->model('member.User_model');
        $this->load->model('trips.trips_model');
        $this->load->model('admin.area_model');
        
        $this->sitename = $GLOBALS['config']['sitename'];
    }

    public function index()
    {
        $city = SITECITYNAME ;
        $data = array();
        $param_uri = $this->uri->segment(2);
        $param_uri = str_replace(array('list_'), '', $param_uri);
        @list($term,$stars) = explode('_', $param_uri);
        $term  = $this->data['term'] = intval($term);
        $stars = $this->data['stars']     = intval($stars);
        $where = array('charge'=>'','term'=>$term,'stars'=>$stars);
        $this->data['expert_array'] =$this->Expert_model->_expert_list($where,'1');
        foreach($this->data['expert_array'] as $k => $v)
        {
            if(empty($v['nickname'])&&empty($v['profile'])&&empty($v['speciality']))
            {
               // unset($this->data['expert_array'][$k]);
            }
        }
        $term_seo = '' ;
        $stars_seo = '' ;
        if(isset($term)&&!empty($term))
        {

            switch ($term) {
                case '1':
                    $term_seo = '一年经验' ;
                    break;
                case '2':
                    $term_seo = '二年经验' ;
                    break;
                case '3':
                    $term_seo = '三-四年经验' ;
                    break;
                case '4':
                    $term_seo = '五-七年经验' ;
                    break;
                case '5':
                    $term_seo = '八-九年经验' ;
                    break;
                case '6':
                    $term_seo = '十年经验' ;
                    break;
            }

        }
        if(isset($stars)&&!empty($stars))
        {

            switch ($stars) {
                case '1':
                    $stars_seo = '一星级' ;
                    break;
                case '2':
                    $stars_seo = '二星级' ;
                    break;
                case '3':
                    $stars_seo = '三星级' ;
                    break;
                case '4':
                    $stars_seo = '四星级' ;
                    break;
                case '5':
                    $stars_seo = '五星级' ;
                    break;
            }

        }
        $this->data['params'] = array(
            'seo'=>array(
                'title'=>$city.$stars_seo.$term_seo.'导游服务_旅游达人',
                'keywords'=>$city.$stars_seo.$term_seo.'导游,'.SITECITYNAME.'旅游达人',
                'desc'=>$city.$stars_seo.$term_seo.'导游，'.$this->sitename.'导游服务，为您提供'.$city.$stars_seo.$term_seo.'导游服务,包括服务报价和服务详情。'.$city.'旅游网'
            ),
            'nav'=>array('current'=>'expert'),
        );
        $this->data['bread'] = '';
        if(!empty($stars)||!empty($term))
        {
            $this->data['bread'] = '&gt; '.$city.$stars_seo.$term_seo.'导游服务' ;
        }
        $this->load->view(TEMPLATE_NAME.'/view_expert_list',$this->data);
    }

    public function detail($id)
    {
        $city = SITECITYNAME ;
        $info = $this->Expert_model->_expert_info($id,array('is_open'=>'1'));
        if(!$info) redirect(site_url('index/index')) ;
        $this->data = $info ;

        $this->load->library('QrCode');
        $qrCode = new QrCode();
        $file_dir = APPPATH.'cache/qrcode/';
        dmkdir($file_dir);
        $file_name = 'qr_expert'.$id.'.png' ;
        $file = $file_dir.$file_name;
        $qr_str = URLPRE.'mobile/member/card/?eid='.$id.'&from=singlemessage&isappinstalled=0'.(DEBUG ? '&debug=1':'') ;
        $qrCode->setText($qr_str);
        $qrCode->setSize(200);
        $qrCode->setPadding(10);
        $qrCode->save($file);
        $qr_img = URLPRE.'application/cache/qrcode/'.$file_name;
        $this->data['params'] = array(
            'seo'=>array(
                'title'=>$info['realname'].'_'.$city.'旅游达人',
                'keywords'=>$info['realname'],
                'desc'=>$info['profile'].$city.'旅游网'
            ),
            'nav'=>array(
                'current'=>'expert'
            )
        );

        $this->data['bread'] = $info['realname'];
        $this->data['qr_img'] = $qr_img;
        $this->load->view(TEMPLATE_NAME.'/view_detail',$this->data);
    }

    public function widget()
    {
        $this->data['list'] = $this->Expert_model->get_recommend_expert(6);
        $this->load->view(TEMPLATE_NAME .'/widget', $this->data);
    }

}